<?php


namespace app\common\order\model;


use app\common\config\logic\DictionaryLogic;
use app\common\config\model\ConfigCompany;
use app\common\product\logic\ProduceLogic;
use app\common\product\logic\StoreCategoryLogic;
use app\common\system\logic\UserLogic;
use think\Model;
use think\model\concern\SoftDelete;

class OrderAdditional extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        'check_time' => 'timestamp',
    ];

    public function getProductAttr($value, $data) {
        $logic = new ProduceLogic();
        return $logic->getProduce($data['product_id'], ['id', 'title', 'titlepic', 'price', 'unit']);
    }

    public function getCategoryAttr($value, $data) {
        $logic = new StoreCategoryLogic();
        return $logic->getStoreCategory($data['category_id'], ['id', 'title', 'order_model']);
    }

    public function getCompanyAttr($value, $data) {
        $dictionaryLogic = new DictionaryLogic();
        return $dictionaryLogic->getItem($data['company_id'], ConfigCompany::class, ['id', 'title', 'short_name']);
    }

    public function getUserAttr($value, $data) {
        $userLogic = new UserLogic();
        return $userLogic->getUser($data['user_id'], ['id', 'realname']);
    }

    public function getCheckTagAttr($value, $data) {
        $index = $data['check_status'];
        $map = [
            -1 => '暂存',
            0 => '待审核',
            1 => '审核中',
            2 => '审核通过',
            3 => '审核驳回'
        ];

        return $map[$index];
    }
}